//
//  MSHomeTitleViewButton.swift
//  SwiftWeibo
//
//  Created by 824810056 on 16/8/16.
//  Copyright © 2016年 DoNews. All rights reserved.
//

import UIKit

class MSHomeTitleViewButton: UIButton {

    init(userName: String?) {
        super.init(frame: CGRect())
        
        var title = userName
        if title == nil {
            title = "首页"
            
            setTitle(title, for: .normal)
            setTitleColor(#colorLiteral(red: 0.4266758859, green: 0.4266631007, blue: 0.4266703427, alpha: 1), for: .normal)
        } else {
            title! += " "
            setTitle(title, for: .normal)
            setTitleColor(#colorLiteral(red: 0.4266758859, green: 0.4266631007, blue: 0.4266703427, alpha: 1), for: .normal)
            setImage(UIImage(named: "navigationbar_arrow_down"), for: .normal)
            setImage(UIImage(named: "navigationbar_arrow_up"), for: .selected)
        }

        titleLabel?.font = UIFont.boldSystemFont(ofSize: 17)
        
        sizeToFit()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
        
        guard let titleLabel = titleLabel,
            let imageView = imageView
        else {
            return
        }
        
        
        titleLabel.frame = CGRect(x: 0, y: 0.5, width: titleLabel.frame.width, height: titleLabel.frame.height)
        imageView.frame = CGRect(x: titleLabel.frame.width, y: 7, width: 13, height: 7)
        
        
    }

}
